package com.qy139.card.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qy139.card.service.ICardInfoService;
import com.qy139.entity.CardInfo;
import com.qy139.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yuhaochen
 * @since 2021-11-30
 */
@RestController
@RequestMapping("/card-info")
public class CardInfoController {
    @Resource
    private ICardInfoService cardInfoService;
    //分页+模糊查所有卡信息
    @GetMapping("/findAllCardInfo")
    public Result findAllCardInfo(Page page, CardInfo cardInfo){
        QueryWrapper<CardInfo> queryWrapper = new QueryWrapper();
        queryWrapper.like("cardnum",cardInfo.getCardnum());
        Page page1 = cardInfoService.page(page,queryWrapper);
        return new Result(page1);
    }

    //新增卡
    @PostMapping("/addCard")
    public Result saveCard(@RequestBody CardInfo cardInfo){
        return cardInfoService.addCard(cardInfo);
    }

    //改、逻辑删除
    @PutMapping("/updCardInfo")
    public Result updCardInfo(@RequestBody CardInfo cardInfo){
        cardInfo.setUpdatetime(new Date());
        return new Result(cardInfoService.saveOrUpdate(cardInfo));
    }
    //关联查询 卡类型
    @GetMapping("/selectAll")
    public Result selectAll(Page<CardInfo> page,Integer cardnum){
        IPage<CardInfo> page1 = cardInfoService.selectALl(page,cardnum);
        return new Result(page1);
    }
}

